package client;
import java.io.*;
import java.net.*;
import java.util.List;

import mill.*;

import util.*;


public class TCPClient
{
	public static void main(String[] args)
	{
		List<MillPark> m_parks;
		List<MillLog> m_logs;
		
		try
		{
			// Create a socket to connect to the server
			Socket connectToServer = new Socket("localhost", 8000);

			// Find the Servers' hostname, and IP address
			InetAddress serverInetAddress = connectToServer.getInetAddress();
			System.out.println("Servers hostname is " + serverInetAddress.getHostName());
			System.out.println("Servers  IP Address is " + serverInetAddress.getHostAddress());

			// Create an input Object stream to receive MillPark objects data from the server
			ObjectInputStream clientInputStreamMP = new ObjectInputStream(connectToServer.getInputStream());
			try {
				m_parks = (List<MillPark>)clientInputStreamMP.readObject();
				System.out.println(m_parks.size());
				System.out.println(m_parks.get(0).get_location());
				System.out.println(m_parks.get(1).get_location());
				System.out.println(m_parks.get(2).get_location());
				System.out.println(m_parks.get(3).get_location());
				System.out.println(m_parks.get(4).get_location());
			 //clientInputStreamMP.close();
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			// Create an input Object stream to receive MillLog objects data from the server
			ObjectInputStream clientInputStreamML = new ObjectInputStream(connectToServer.getInputStream());
			try {
				m_logs = (List<MillLog>)clientInputStreamML.readObject();

				for (MillLog millLog : m_logs)
				{
					System.out.println("Logged serieal numbers: " + millLog.getSerialNumber());
					
				}
				System.out.println("Total number of milllogs: " + m_logs.size());
			 //clientInputStreamML.close();
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		catch (IOException ex)
		{
			System.err.println(ex);
		}
	}
}
